/**************************************************************

Project: L-Spider
Module: Beam timer routines

***************************************************************/

void beam_timer_start( unsigned int threshold ) {
    PR2 = threshold;
    T2CON |= 0b00000100;  // Set the TMR2ON bit
} // beam_timer_start()

//========================================================

void beam_timer_stop() {
    T2CON &= 0b11111011;  // Clear the TMR2ON bit
} // beam_timer_stop()

//========================================================

void beam_timer_reset() {
    TMR2 = 0;
    PIR1 &= 0b11111101;  // Reset TMR2 overflow flag
} // beam_timer_reset()

//========================================================

unsigned char beam_timer_overflow() {
    return ( PIR1 & 0b00000010 ) >> 1;  // If bit 2 (T0IF) is set, will return 1
} // beam_timer_overflow()

// *** End of file ***